<#if matchProjectItem??>
<script type="text/javascript">
	function doSearchMatchProArticle(value) {
		
	}
	
	//表格查询  
	function reloadMatchProArticle() {
		var params = matchProArticle_list.datagrid('options').queryParams; //先取得 datagrid 的查询参数  
		printLog(params);
		matchProArticle_list.datagrid('reload'); //设置好查询参数 reload 一下就可以了  
		matchProArticle_list.datagrid('unselectAll');
		matchProArticle_list.datagrid('uncheckAll');
	}


	function addMatchProArticle() {
// 		createFromWindow("新增信息", "matchProArticle.do?editMatchProArticle", "matchProArticle.do?saveMatchProArticle",
// 				function(data) {
// 					reloadMatchProArticle();
// 				});

		createFromWindowOptions({
			title:"新增信息",
			maximizable:true,
			width:600,
			height:300,
			saveButtonText:'下一步',
			href:"matchProArticle.do?selectMatchProType&matchProjectId=${(matchProjectItem.id)!}",
			callback:function(d) {
				var formData = d.form("getData");
				formData.matchProjectId=${(matchProjectItem.id)!};
				printLog(formData);
				addActionMatchProArticle(formData.artType);
			},
			enableSaveButton:true
		});
		
	}
	
	function addActionMatchProArticle(artType) {
		createFromWindowOptions({
			title:"新增信息",
			maximizable:true,
			width:document.body.clientWidth,
			height:document.body.clientHeight,
			skipFormValidate:true,
			href:"matchProArticle.do?editMatchProArticle&matchProjectId=${(matchProjectItem.id)!}&artType="+artType,
			callback:function(d) {
				syncCkeditToTextarea();
				var validate = d.form("validate");
	            printLog(validate);
	            if (validate) {
	            	var formData = d.form("getData");
					formData.matchProjectId = ${(matchProjectItem.id)!};
					$.ajax({
		           	  type: 'POST',
		           	  url: "matchProArticle.do?saveMatchProArticle",
		              dataType : 'json',  
		           	  data: formData,
		           	  success: function(data) {
		           		  showMsg(data.msg);
		           		  if(data.success) {
		           			reloadMatchProArticle();
			           	  }
		           	  },
			          error:function(data,textstatus){
			        	  showMsg('请求异常');
			          }  
		           	});
	            } else {
	                 return false;
	            }
				
			},
			enableSaveButton:true
		});
	}
	
	function deleteMatchProArticle() {
		var rows = matchProArticle_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('matchProArticle.do?deleteMatchProArticleItems&matchProjectId=${(matchProjectItem.id)!}',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadMatchProArticle();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}

	function editMatchProArticle() {
		var rows = matchProArticle_list.datagrid('getChecked');
		printLog(rows);
		if (rows&&rows.length>0) {
			if(rows.length>1) {
				showMsg('请选择一条操作记录.');
				return;
			}
// 			createFromWindow("编辑信息", "matchProArticle.do?editMatchProArticle&matchProArticleId=" + rows[0].id,
// 					"matchProArticle.do?saveMatchProArticle", function(data) {
// 						reloadMatchProArticle();
// 					},true);
			createFromWindowOptions({
				title:"编辑信息",
				maximizable:true,
				width:document.body.clientWidth,
				height:document.body.clientHeight,
				skipFormValidate:true,
				href:"matchProArticle.do?editMatchProArticle&matchProArticleId=" + rows[0].id,
				callback:function(d) {
					syncCkeditToTextarea();
					var validate = d.form("validate");
		            printLog(validate);
		            if (validate) {
		            	var formData = d.form("getData");
		            	$.ajax({
			           	  type: 'POST',
			           	  url: "matchProArticle.do?saveMatchProArticle&matchProjectId=${(matchProjectItem.id)!}",
			              dataType : 'json',  
			           	  data: formData,
			           	  success: function(data) {
			           		  showMsg(data.msg);
			           		  if(data.success) {
			           			reloadMatchProArticle();
				           	  }
			           	  },
				          error:function(data,textstatus){
				        	  showMsg('请求异常');
				          }  
			           	});
		            } else {
		                 return false;
		            }
				},
				enableSaveButton:'1'!=rows[0].publishStatu //已发布不能在编辑了
			});
		} else {
			showMsg('请选择操作记录.');
		}

	}
	
	
	function clearMatchProArticleSearch() {
		setGridSearchParams('matchProArticle_list','matchProArticleSearchForm',true,reloadMatchProArticle);
	}
	
	//根据条件查询
	function matchProArticleSearch() {
		setGridSearchParams('matchProArticle_list','matchProArticleSearchForm',false,reloadMatchProArticle);
	}
	
	function syncCkeditToTextarea() {
// 		debugger;
		for ( instance in CKEDITOR.instances ) {
			CKEDITOR.instances[instance].updateElement();
		}
	}
	
	function onDblClickMatchProArticleRow(rowIndex, rowData) {
// 		createFromWindow("编辑信息", "matchProArticle.do?editMatchProArticle&matchProArticleId=" + rowData.id,
// 					"matchProArticle.do?saveMatchProArticle", function(data) {
// 						reloadMatchProArticle();
// 					},true);
		createFromWindowOptions({
			title:"编辑信息",
			maximizable:true,
			width:document.body.clientWidth,
			height:document.body.clientHeight,
			skipFormValidate:true,
			href:"matchProArticle.do?editMatchProArticle&matchProjectId=${(matchProjectItem.id)!}&matchProArticleId=" + rowData.id,
			callback:function(d) {
				syncCkeditToTextarea();
				var validate = d.form("validate");
	            printLog(validate);
	            if (validate) {
	            	var formData = d.form("getData");
					$.ajax({
		           	  type: 'POST',
		           	  url: "matchProArticle.do?saveMatchProArticle",
		              dataType : 'json',  
		           	  data: formData,
		           	  success: function(data) {
		           		  showMsg(data.msg);
		           		  if(data.success) {
		           			reloadMatchProArticle();
			           	  }
		           	  },
			          error:function(data,textstatus){
			        	  showMsg('请求异常');
			          }  
		           	});
	            } else {
	                 return false;
	            }
	            
				
			},
			enableSaveButton:'1'!=rowData.publishStatu //已发布不能在编辑了
		});
		
	}
	
	
	function publishMatchProArticle() {
		var rows = matchProArticle_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要发布吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('matchProArticle.do?publishMatchProArticleItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadMatchProArticle();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	
	function submitMatchProArticle() {
		var rows = matchProArticle_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要提交吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('matchProArticle.do?submitMatchProArticleItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadMatchProArticle();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	
	function revokeMatchProArticle() {
		var rows = matchProArticle_list.datagrid('getChecked');
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要撤销吗?',function(r){
	            if (r){
	            	var ids = "";
	            	for(var i=0; i<rows.length; i++){
	            		ids += rows[i].id+",";
	            	}
	                $.post('matchProArticle.do?revokeMatchProArticleItems',{ids:ids},function(result){
	                    if (result.success){
	                    	reloadMatchProArticle();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
	}
	
	function operationsManagerMatchProArticle(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = matchProject_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			createFromWindowOptions({
				title:"查看信息",
				maximizable:true,
				width:document.body.clientWidth,
				height:document.body.clientHeight,
				skipFormValidate:true,
				href:"matchProArticle.do?editMatchProArticle&matchProjectId=${(matchProjectItem.id)!}&matchProArticleId=" + id,
				callback:function(d) {
					syncCkeditToTextarea();
					var validate = d.form("validate");
		            printLog(validate);
		            if (validate) {
		            	var formData = d.form("getData");
						$.ajax({
			           	  type: 'POST',
			           	  url: "matchProArticle.do?saveMatchProArticle",
			              dataType : 'json',  
			           	  data: formData,
			           	  success: function(data) {
			           		  showMsg(data.msg);
			           		  if(data.success) {
			           			reloadMatchProArticle();
				           	  }
			           	  },
				          error:function(data,textstatus){
				        	  showMsg('请求异常');
				          }  
			           	});
		            } else {
		                 return false;
		            }
		            
					
				},
				enableSaveButton:false //已发布不能在编辑了
			});
		} else {
			showMsg('请选择查看记录.');
		}
	}
	
	function operationsEditMatchProArticle(id) {
		var editEnable = true;
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = matchProject_list.datagrid('getSelections');
			id = rows[0].id;
			editEnable = '1'!=rows[0].publishStatu
		}
		if (id) {
			createFromWindowOptions({
				title:"编辑信息",
				maximizable:true,
				width:document.body.clientWidth,
				height:document.body.clientHeight,
				skipFormValidate:true,
				href:"matchProArticle.do?editMatchProArticle&matchProjectId=${(matchProjectItem.id)!}&matchProArticleId=" + id,
				callback:function(d) {
					syncCkeditToTextarea();
					var validate = d.form("validate");
		            printLog(validate);
		            if (validate) {
		            	var formData = d.form("getData");
						$.ajax({
			           	  type: 'POST',
			           	  url: "matchProArticle.do?saveMatchProArticle",
			              dataType : 'json',  
			           	  data: formData,
			           	  success: function(data) {
			           		  showMsg(data.msg);
			           		  if(data.success) {
			           			reloadMatchProArticle();
				           	  }
			           	  },
				          error:function(data,textstatus){
				        	  showMsg('请求异常');
				          }  
			           	});
		            } else {
		                 return false;
		            }
				},
				enableSaveButton:editEnable //已发布不能在编辑了
			});
		} else {
			showMsg('请选择编辑记录.');
		}
	}
	
	function operationsDeleteMatchProArticle(id) {
		if (id == undefined) {//点击右键菜单才会触发这个
			var rows = matchProject_list.datagrid('getSelections');
			id = rows[0].id;
		}
		if (id) {
			$.messager.confirm('询问','你确认要删除吗?',function(r){
	            if (r){
	                $.post('matchProArticle.do?deleteMatchProArticleItems&matchProjectId=${(matchProjectItem.id)!}',{ids:id},function(result){
	                    if (result.success){
	                    	reloadMatchProArticle();    
	                    }
	                    showMsg(result.msg);
	                },'json');
	            }
	        });
		} else {
			showMsg('请选择操作记录.');
		}
	}
</script>

<#assign operations = "[\{shiro:'match:matchProArticle:look',title:'查看',onClick:'operationsManagerMatchProArticle'}
	  				   ]"/>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
<!-- 	onDblClickRow="onDblClickMatchProArticleRow(rowIndex, rowData)" -->
		<@eu.datagrid id="matchProArticle_list" toolbar="#matchProArticlelist_search" idField="id"  url="matchProArticle.do?loadList&editStatu=zs&matchProjectId=${(matchProjectItem.id)!}" rownumbers="true" 
			 item="com.xdtech.match.vo.MatchProArticleItem" operations="${operations!}"/>
		
		<div id="matchProArticlelist_search">
			<div style="margin-bottom:5px;padding-left:5px;margin-top: 5px;">
				<form id="matchProArticleSearchForm">
					<!-- 防止form表单里只有一个text元素时候，按enter键自动提交问题 -->
					<input style="display:none" />
					<table>
						<tr>
							<td>
								当前赛事：${(matchProjectItem.matName)!}
							</td>
						</tr>
					</table>
					<table>
						<tr>
							<td>项目名称：</td>
							<td><input class="easyui-validatebox textbox" name="artName" style="width: 150px"/></td>
							<td>单位名称：</td>
							<td><input class="easyui-validatebox textbox" name="companyName" style="width: 150px"/></td>
							
							<td>项目类别：</td>
							<td><@eu.comboBox name="artType" url="common.do?loadComboBox&key=MATCH_ART_TYPE" /></td>
							<td>团队名称：</td>
							<td><input class="easyui-validatebox textbox" name="teamName" style="width: 150px"/></td>
						</tr>
						<tr>
							<td>类别：</td>
							<td><@eu.comboBox name="universityLevel" url="common.do?loadComboBox&key=MATCH_UNIVERSITY_LEVEL" /></td>
						
							<td>发布状态：</td>
							<td><@eu.comboBox name="publishStatu" url="common.do?loadComboBox&key=MATCH_PUBLISH_STATU" /></td>
<!-- 							<td>提交人：</td> -->
<!-- 							<td><input class="easyui-validatebox textbox" name="submitPerson" style="width: 150px"/></td> -->
<!-- 							<td>提交状态：</td> -->
<!-- 							<td><@eu.comboBox name="submitStatu" url="common.do?loadComboBox&key=MATCH_SUBMIT_STATU" /></td> -->
							<td>
								<@eu.linkbutton showName="查询" iconCls="icon-search" onclick="matchProArticleSearch()"/>
	 					 		<@eu.linkbutton showName="清空" iconCls="icon-clear" onclick="clearMatchProArticleSearch()"/>
 					 		</td>
						</tr>
					</table>
				</form>
				
			</div>
			<div id="matchProArticle_toolbar" style="height: auto">
<!-- 				<@eu.linkbutton showName="新增" shiro="match:matchProArticle:add" iconCls="icon-add" onclick="addMatchProArticle()"/> -->
				<@eu.linkbutton showName="提交" shiro="match:matchProArticle:submit" iconCls="icon-remove" onclick="submitMatchProArticle()"/>
				<@eu.linkbutton showName="发布" shiro="match:matchProArticle:publish" iconCls="icon-remove" onclick="publishMatchProArticle()"/>
				<@eu.linkbutton showName="撤销" shiro="match:matchProArticle:revoke" iconCls="icon-remove" onclick="revokeMatchProArticle()"/>
<!-- 				<@eu.linkbutton showName="删除" shiro="match:matchProArticle:delete" iconCls="icon-remove" onclick="deleteMatchProArticle()"/> -->
<!-- 				<@eu.linkbutton showName="编辑" shiro="match:matchProArticle:edit" iconCls="icon-edit" onclick="editMatchProArticle()"/> -->
				<@eu.linkbutton showName="刷新" shiro="match:matchProArticle:refresh" iconCls="icon-reload" onclick="reloadMatchProArticle()"/>
			</div>
		</div>
	</div>
</div>
<#else>
	未进入赛事选择操作，无法进行相关对应参赛项目操作，请进行参赛报名登录或联系管理员！
</#if>